/*
 * Copyright (c) zhg2yqq.com Corp.
 * All Rights Reserved.
 */
package com.zhg2yqq.wheels.security.multi;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * 自定义身份信息
 *
 * @author zhg2yqq, 2023年3月16日
 * @version zhg2yqq v1.0
 */
public abstract class CustomAuthenticationToken extends UsernamePasswordAuthenticationToken {
    private static final long serialVersionUID = 1L;
    private final String type;

    protected CustomAuthenticationToken(String type, Object principal, Object credentials) {
        super(principal, credentials);
        this.type = type;
    }

    public String getType() {
        return type;
    }

    /**
     * 前置检查，例如验证码校验
     *
     * @param checkHelper
     * @throws AuthenticationException
     */
    public void prevAuthenticationCheck(TokenCheckHelper checkHelper)
            throws AuthenticationException {
    }

    /**
     * 创建身份认证信息
     *
     * @param userDetailsService
     * @return
     * @throws AuthenticationException
     */
    public abstract UserDetails retrieveUser(UserDetailsService userDetailsService)
            throws AuthenticationException;

    /**
     * 过程检查，例如密码校验
     *
     * @param checkHelper
     * @throws AuthenticationException
     */
    protected void postAuthenticationCheck(UserDetails userDetails, TokenCheckHelper checkHelper)
            throws AuthenticationException {
    }
}
